package com.yc.vote.servlet;

import com.google.gson.Gson;
import com.yc.vote.entity.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "MyInfoServlet", value = "/myinfo")
public class MyInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Result result;
        Object user = request.getSession().getAttribute("myinfo");
        if(user == null){
            result = new Result(0, "未登录", null);
        } else {
            result = new Result(1, "已登录", user);
        }
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().append(new Gson().toJson(result));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
